package com.yingpai.fitness.dvp_2_0.main.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;

import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.util.SharedPreferencesHelp;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.bean.SplashBean;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Constant;
import com.yingpai.fitness.entity.wx.TokenBean;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ASUS on 2019/2/21.
 */

public class WebViewActivity extends CommonActivity {

    @BindView(R.id.webview)
    WebView webview;
    @BindView(R.id.back)
    ImageView back;
    private SplashBean splashBean;
    private TokenBean tokenBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.activity_webview);
    }

    @Override
    protected void initView() {
        tokenBean = (TokenBean) SharedPreferencesHelp.getBean(Constant.TOKENBEAN);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            splashBean = (SplashBean) bundle.getSerializable("splash");
            setTitle(splashBean.getData().getTitle());
            webview.getSettings().setUseWideViewPort(true);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.loadUrl(splashBean.getData().getUrl());
        }

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toNextActivity();
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    @OnClick({R.id.back})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {
            case R.id.back:
                toNextActivity();
                break;
        }
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        toNextActivity();
    }

    private void toNextActivity() {
        if (tokenBean == null || TextUtils.isEmpty(tokenBean.getRegisterId())) {
            startFinishActivity(LoginAndRegisterActivity.class);
        } else {
            startFinishActivity(HomeActivity.class);
        }
    }
}
